//Vector deque list and string are allocated in heap for their elements. So, sizeof these container objects are
//a constant value like this program shows.

#include <vector>
#include <iostream>
#include <iterator>
#include <deque>
#include <list>
#include <algorithm>
#include <string>

using namespace std ;

int a[] = { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19 } ;

template <typename Cont>
void frontInsertion( Cont & ci )
{
	copy ( a, a + sizeof a/ sizeof(typename Cont::value_type), front_inserter(ci) ) ;
	copy ( ci.begin(), ci.end(), ostream_iterator<typename Cont::value_type>(cout, " ") ) ;
	cout << endl ;
}

template <typename Cont>
void backInsertion( Cont & ci )
{
	copy ( a, a + sizeof a/ sizeof(typename Cont::value_type), back_inserter(ci) ) ;
	copy ( ci.begin(), ci.end(), ostream_iterator<typename Cont::value_type>(cout, " ") ) ;
	cout << endl ;
}

template <typename Cont>
void midInsertion( Cont & ci )
{
	typename Cont::iterator it = ci.begin() ;
	++it; ++it; ++it;
	
	copy ( a, a + sizeof a / (sizeof(typename Cont::value_type)*2), inserter(ci, it) ) ;
	copy ( ci.begin(), ci.end(), ostream_iterator<typename Cont::value_type>(cout, " ") ) ;
	cout << endl ;
}

template<typename Cont>
void contSizeof ( string prompt, Cont & cn )
{
    cout<< "sizeof, " << prompt << ":" << sizeof(cn) << endl ;
}



int main ( )
{
	deque<int>  di ;
	list<int>   li ;
	vector<int> vi ;

///////////////////////
    contSizeof("di", di) ;
    contSizeof("li", li) ;
    contSizeof("vi", vi) ;
/////////////////////////

	frontInsertion(di) ;
	frontInsertion(li) ;

	di.clear() ;
	li.clear() ;

	backInsertion ( vi ) ;
	backInsertion ( di ) ;
	backInsertion ( li ) ;

///////////////////////
    contSizeof("di", di) ;
    contSizeof("li", li) ;
    contSizeof("vi", vi) ;
/////////////////////////

	midInsertion ( vi ) ;
	midInsertion ( di ) ;
	midInsertion ( li ) ;

///////////////////////
    contSizeof("di", di) ;
    contSizeof("li", li) ;
    contSizeof("vi", vi) ;
/////////////////////////

    string str = "what is your name ?" ;
    contSizeof("str", str) ;


	return 0 ;
}

//////////////////////////////
//---------run sizeof----------
//sizeof, di:40
//sizeof, li:8
//sizeof, vi:12
//19 17 15 13 11 9 7 5 3 1 
//19 17 15 13 11 9 7 5 3 1 
//1 3 5 7 9 11 13 15 17 19 
//1 3 5 7 9 11 13 15 17 19 
//1 3 5 7 9 11 13 15 17 19 
//sizeof, di:40
//sizeof, li:8
//sizeof, vi:12
//1 3 5 1 3 5 7 9 7 9 11 13 15 17 19 
//1 3 5 1 3 5 7 9 7 9 11 13 15 17 19 
//1 3 5 1 3 5 7 9 7 9 11 13 15 17 19 
//sizeof, di:40
//sizeof, li:8
//sizeof, vi:12
//sizeof, str:4
//////////////////////////////////
